#include <iostream>
using namespace std;
#define N ((long int)1e5 + 10)
int que[N];
int b = 0;
int e = 0;
void push(int x)
{
    que[e++] = x;
}
void pop()
{
    ++b;
}
bool empty()
{
    return b == e;
}
int query()
{
    return que[b];
}
int main()
{
    int m;
    cin >> m;
    while (m--)
    {
        string str;
        cin >> str;
        if (str == "push")
        {
            int x;
            cin >> x;
            push(x);
        }
        else if (str == "pop")
        {
            pop();
        }
        else if (str == "empty")
        {
            cout << (empty() ? "YES" : "NO") << endl;
        }
        else if (str == "query")
        {
            cout << query() << endl;
        }
    }
    return 0;
}